set more off

	
use Data/Estimation_sample.dta, clear
	
	gen nexis_buildings  = ROOFME/PROOFME
		
		
	gen roofratio = ROOFME/ROOFTI
	gen roofratiobuildings = roofratio*nexis_buildings
		
	gen roofrelativeIV = (roofratio*nexis_buildings/[moduleprice])/1000

		format quarter %tq

	
	
  summ year
  local miny = r(min)
  local maxy = r(max)
  
  forval y = `miny'(1)`maxy' {
  
	gen year_cum`y' = (year ==`y')* cuminstall
	gen year_roof`y' = (year ==`y')*roofrelativeIV 
	
	label variable year_cum`y' "`y'"
	}
  
  
	
	xi: xtivreg2 green_p   year_cum*  i.quarter  [aweight =NCust	] , fe cluster(postcode) 

	eststo model1
	
	summ green_plan [aweight =NCust	] if e(sample)
    local meandepvar=round(`r(mean)',.001)
	
	outreg2 using Analysis/FEyear_postcode, bdec(3) label ctitle("FE")   ///
	keep(quarter*) addtext(Postcode FE, Yes, Year-Quarter FE, Yes, Mean dep var, `meandepvar') ///
	tex(fragment pretty) nonotes replace
 

 
 
	

	coefplot (model1, keep(year_*) mcolor(gs0) ciopts(lcolor(gso)) msymbol(o)), vertical ///
	   legend(off) yline(0)  ///
	xtitle("Year") label ytitle("Effect of Solar Rooftops on Green Power Purchases")

	
  
  
  graph export Analysis/FEbyyear.png, replace

	
	
	

	coefplot (model1, keep(*2010 *2011 *2012 *2013 *2014 *2015 *2016) mcolor(gs0) ciopts(lcolor(gso)) msymbol(o)), vertical ///
	   legend(off) yline(0)  ///
	xtitle("Year") label ytitle("Effect of Solar Rooftops on Green Power Purchases")

	
  
  
  graph export Analysis/FEbyyear_post2010.png, replace
	
	

	coefplot (model1, keep(*2011 *2012 *2013 *2014 *2015 *2016) mcolor(gs0) ciopts(lcolor(gso)) msymbol(o)), vertical ///
	   legend(off) yline(0)  ///
	xtitle("Year") label ytitle("Effect of Solar Rooftops on Green Power Purchases")

	
  
  
  graph export Analysis/FEbyyear_post2011.png, replace

	
